package com.github.shiqiyue.app.api.sapi.result.permission;


import com.github.shiqiyue.app.common.entity.TreeNode;
import com.github.shiqiyue.app.modules.sys.entity.Permission;
import lombok.Data;

import java.util.List;

/***
 * 权限树VO
 * @author wenyao.wu
 * @date 2018/10/15
 */
@Data
public class PermissionTreeDTO  implements TreeNode {

    private Long id;

    /**
     * 名称
     */
    private String name;

    /**
     * 类型,1-菜单，2-按钮
     */
    private Integer type;

    /**
     * 权限编码
     */
    private String code;

    /**
     * 是否启用,-1-不启用,1-启用
     */
    private Integer enable;

    /****
     * 上级权限id
     */
    private Long pid;


    private List<PermissionTreeDTO> children;

    public PermissionTreeDTO() {
    }

    public static PermissionTreeDTO newInstance(Permission permission){
        PermissionTreeDTO permissionTreeDTO = new PermissionTreeDTO();
        permissionTreeDTO.setId(permission.getId());
        permissionTreeDTO.setName(permission.getName());
        permissionTreeDTO.setCode(permission.getCode());
        permissionTreeDTO.setPid(permission.getPid());
        permissionTreeDTO.setEnable(permission.getEnable().getValue());
        permissionTreeDTO.setType(permission.getType().getValue());
        return permissionTreeDTO;
    }

    @Override
    public void setChildren(List children) {
        this.children = children;
    }


}
